package com.yx.cloud.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.yx.cloud.R;
import com.yx.cloud.base.BaseActivity;
import com.yx.cloud.constant.Constants;
import com.yx.cloud.map3d.Room3DSurfaceView;
import com.yx.cloud.utils.SharedPrefsUtil;
import com.iot.product.sweeper.bean.AreaInfo;
import com.iot.product.sweeper.bean.CleanRecord;
import com.iot.common.utils.LogUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/2/21.
 */

public class CleanRecordDetail3DActivity extends BaseActivity {
    private static final String TAG = "RecordDetailActivity";
    TextView tvStartTime;
    TextView tvArea;
    TextView tvTime;
    TextView tvCleanMode;
    ImageView ivStopNormal;
    TextView tvStopNormal;
    ImageView iv_return;

    private String recordData;
    private Room3DSurfaceView yxMapView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.cleanrecord_detail_3d_activity);
        initView();

        recordData = SharedPrefsUtil.getValue(this, "cleanRecorData", "recordData", "");
        Gson gson = new Gson();
        CleanRecord cleanRecordBean = gson.fromJson(recordData, CleanRecord.class);
        initTestRecord(cleanRecordBean);
    }

    private void initView() {
        iv_return = findViewById(R.id.iv_clean_detail_return);
        iv_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        tvStartTime = (TextView) findViewById(R.id.tv_clean_start_time);

        tvArea = (TextView) findViewById(R.id.tv_cleaningArea);

        tvTime = (TextView) findViewById(R.id.tv_cleaningTime);

        tvCleanMode = (TextView) findViewById(R.id.tv_clean_mode);

        ivStopNormal = (ImageView) findViewById(R.id.iv_clean_stop_mode);

        tvStopNormal = findViewById(R.id.tv_clean_stop_mode);

        yxMapView = findViewById(R.id.map_3d_clean_record_detail);

    }

    public void initTestRecord(CleanRecord cleanRecordBean) {
        List<AreaInfo> areaInfoList = cleanRecordBean.getMap().getArea();
        AreaInfo areaInfo = new AreaInfo();
        areaInfo.setType(AreaInfo.TYPE_CLEAN);
        ArrayList<Double> point = new ArrayList<>();
        point.add(0d);
        point.add(12d);
        point.add(12d);
        point.add(12d);
        point.add(12d);
        point.add(0d);
        point.add(0d);
        point.add(0d);
        areaInfo.setBorder(point);
        areaInfoList.add(areaInfo);

        areaInfo = new AreaInfo();
        areaInfo.setType(AreaInfo.TYPE_FORBIDDEN);
        point = new ArrayList<>();
        point.add(-10d);
        point.add(0d);
        point.add(0d);
        point.add(0d);
        point.add(0d);
        point.add(-10d);
        point.add(-10d);
        point.add(-10d);
        areaInfo.setBorder(point);
        areaInfoList.add(areaInfo);

        areaInfo = new AreaInfo();
        areaInfo.setType(AreaInfo.TYPE_FORBIDDEN_LINE);
        point = new ArrayList<>();
        point.add(-13d);
        point.add(0d);
        point.add(30d);
        point.add(0d);
        areaInfo.setBorder(point);
        areaInfoList.add(areaInfo);

        areaInfo = new AreaInfo();
        areaInfo.setType(AreaInfo.TYPE_FORBIDDEN_LINE);
        point = new ArrayList<>();
        point.add(200d);
        point.add(200d);
        point.add(190d);
        point.add(200d);
        areaInfo.setBorder(point);
        areaInfoList.add(areaInfo);

        areaInfo = new AreaInfo();
        areaInfo.setType(AreaInfo.TYPE_FORBIDDEN_LINE);
        point = new ArrayList<>();
        point.add(200d);
        point.add(200d);
        point.add(200d);
        point.add(190d);
        areaInfo.setBorder(point);
        areaInfoList.add(areaInfo);

        areaInfo = new AreaInfo();
        areaInfo.setType(AreaInfo.TYPE_FORBIDDEN_MOP);
        point = new ArrayList<>();
        point.add(-1d);
        point.add(1d);
        point.add(1d);
        point.add(1d);
        point.add(1d);
        point.add(-1d);
        point.add(-1d);
        point.add(-1d);
        areaInfo.setBorder(point);
        areaInfoList.add(areaInfo);
        if (cleanRecordBean != null) {
            initWidget(cleanRecordBean);
        }
    }

    private void initWidget(CleanRecord recordData) {
        LogUtils.ls(" 清扫 ffffff------------------------------" + new Gson().toJson(recordData));
        //地图控件显示地图
        yxMapView.refreshMap(recordData.getMap());

        String startTime = recordData.getStartTime();
        //tvStartTime.setText(DateUtils.timeStamp2Date(startTime, "yyyy-MM-dd HH:mm:ss"));
        tvStartTime.setText(startTime);

        int sweepArea = recordData.getArea();
        tvArea.setText(sweepArea + "");

        int sweepTime = recordData.getCleanTime();
        tvTime.setText(sweepTime + "");

        int cleanMode = recordData.getCleanMode();
        switch (cleanMode) {
            /*case Constants.CLEAN_MODE_UNKNOW:
                tvCleanMode.setText("未知");
                break;*/
            case Constants.CLEAN_MODE_DOT:
                tvCleanMode.setText(getString(R.string.U_SpotClean));
                break;
            case Constants.CLEAN_MODE_AREA:
                tvCleanMode.setText(getString(R.string.U_RoomClean));
                break;
            case Constants.CLEAN_MODE_DOT_YUDI:
                tvCleanMode.setText(getString(R.string.U_SpotClean));
                break;
            case Constants.CLEAN_MODE_ROOM:
                tvCleanMode.setText(getString(R.string.U_RoomClean));
                break;
            case Constants.CLEAN_MODE_AUTO_SPLIT_ROOM:
                //tvCleanMode.setText(getString(R.string.Intelligent_partition_cleaning));
                break;
            case Constants.CLEAN_MODE_DEPTH:
                //tvCleanMode.setText(getString(R.string.Deep_cleaning));
                break;
            case Constants.CLEAN_MODE_EXTEND:
                //tvCleanMode.setText(getString(R.string.Yanbian_cleaning));
                break;
            case Constants.CLEAN_MODE_DEMO:
                //tvCleanMode.setText(getString(R.string.demo_mode));
                break;
            case Constants.CLEAN_MODE_EXPLORE:
                //tvCleanMode.setText(getString(R.string.Explore_mode));
                break;
            case Constants.CLEAN_MODE_ALL:
            default:
                tvCleanMode.setText(getString(R.string.U_AutoClean));
        }

        int isDoneNormal = recordData.getIsDoneNormal();
        if (isDoneNormal == 1) {
            ivStopNormal.setImageResource(R.mipmap.clean_accomplish_icon);
            tvStopNormal.setText(getString(R.string.MO_Clean_Complete));
        } else if (isDoneNormal == 0) {
            ivStopNormal.setImageResource(R.mipmap.clean_interrupt_icon);
            tvStopNormal.setText(getString(R.string.MO_Clean_Abort));
        }
    }
}
